<?php
/**
 * contact : 刘经理 19326416371
 * company : 版权所属 四川北星惯牌科技有限公司
 **/
namespace app\common\model\Platform;

use think\Model;


class Log extends Model
{

    const DIRECTIVE_INCOME = 2;
    const DIRECTIVE_OUT = 1;

    const TYPE_TEAM = 1;
    const TYPE_MATCH = 2;
    const TYPE_INVITE = 3;
    const TYPE_ACTIVE = 4;
    const TYPE_INVITE_STORE = 5;
    const TYPE_RECHARGE = 6;
    const TYPE_RECHARGE_PROXY_REWARD = 7;
    const TYPE_PROXY_STORE_TEAM_REWARD = 8;
    const TYPE_PROXY_CAPTAIN_TEAM_REWARD = 9;
    const TYPE_SYS_ADJUST = 10;
    const TYPE_SYS_VIP_PRESENT = 11;

    const DIRECTIVE_INCOME_MEMO = '进账';
    const DIRECTIVE_OUT_MEMO = '出账';
    const TYPE_TEAM_MESSAGE = '%s 组队%s %.2f ';

    const TYPE_MATCH_MESSAGE = '%s 赛事%s %.2f ';

    const TYPE_INVITE_MESSAGE = '%s 邀请%s %.2f ';

    const TYPE_ACTIVE_MESSAGE = '%s 活动%s %.2f ';
    const TYPE_INVITE_STORE_MESSAGE = '%s 门店邀请%s %.2f ';
    const TYPE_RECHARGE_MESSAGE = '%s 充值%s %.2f ';
    const TYPE_RECHARGE_PROXY_REWARD_MESSAGE = '%s 充值代理奖励%s %.2f ';
    const TYPE_PROXY_STORE_TEAM_REWARD_MESSAGE = '%s 门店组队代理奖励%s %.2f ';
    const TYPE_PROXY_CAPTAIN_TEAM_REWARD_MESSAGE = '%s 队长组队代理奖励%s %.2f ';
    const TYPE_SYS_ADJUST_MESSAGE = '%s 系统调整%s %.2f ';
    const TYPE_SYS_VIP_PRESENT_MESSAGE = '%s 系统赠送VIP%s %.2f ';
    // 表名
    protected $name = 'platform_log';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'type_text',
        'create_time_text',
        'update_time_text'
    ];
    

    
    public function getTypeList()
    {
        return ['1' => __('Type 1'), '2' => __('Type 2'), '3' => __('Type 3'), '4' => __('Type 4')];
    }


    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getCreateTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getUpdateTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['update_time']) ? $data['update_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setCreateTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setUpdateTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


    public function user()
    {
        return $this->belongsTo('app\admin\model\User', 'recipient', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
